'use strict';

var _html = document.getElementsByTagName("html")[0];
_html.style.fontSize = document.documentElement.clientWidth / 750 * 100 + "px";
window.onresize = function() {
    _html.style.fontSize = document.documentElement.clientWidth / 750 * 100 + "px";
};

var URL;
var localUrl;

// if ((/(192\.168\.1\.)|(localhost)/).test(window.location.href)) {
//     URL = 'http://192.168.1.50:9091/';
//     localUrl = 'http://appiwin.anjintech.com/'
// } else {
//     URL = 'https://appiwin.anjintech.com/'
//     localUrl = 'http://appiwin.anjintech.com/'

// }

URL = 'http://192.168.1.50:9091/';
localUrl = 'http://appiwin.anjintech.com/'

//请求
function requestFun(url, params) {
    url = URL + url + '?encryptData=' + encodeURIComponent(JSON.stringify({ data: params }));
    var deferred = $.Deferred();
    $.ajax({
        url: url,
        dataType: "json",
        type: "post",
        success: function(data) {
            if (data.data.resultCode != '0000') {
                toast(data.data.resultMessage);
            }
            deferred.resolve(data.data);
        },
        error: function(data) {
            console.log(data);
            console.warn("error!");
            deferred.reject(data);
        }
    });

    return deferred.promise();
}

function download(e) {
    var e = e || window.event;
    window.location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.anyin.app';
    e.stopPropagation();
}

function toast(txt) {
    if (!txt) return;
    $('#toast-message').remove();
    var str = $('<div id="toast-message">' + txt + '</div>');
    str.appendTo($('body'));
    str.stop().fadeOut(3000);
}

var au = document.getElementById('au');

function changeAudio() {
    if (!$('#au').attr('src')) return false;
    if (!au.paused) {
        au.pause();
        $('.audio .btn img').attr('src', 'image/btn_play.png');
    } else {
        au.play();
        $('.audio .btn img').attr('src', 'image/btn_pause.png');
    }
}

function changeTitle(title) {
    var $body = $('body');
    document.title = title;
    var $iframe = $('<iframe src="//m.baidu.com/favicon.ico"></iframe>').on('load', function () {
        setTimeout(function () {
            $iframe.off('load').remove()
        }, 0)
    }).appendTo($body);
}